/**
 * Created by ideabobo on 14-6-28.
 */

var rootUrl = "http://127.0.0.1:8088/";
var fileurl = rootUrl+"upload/";
var clientUrl = rootUrl+"database/";
var uploadUrl = rootUrl+"database/upload";
var downloadUrl = rootUrl+"download";





function toUrl(fid){
    changePage("webcontent");
    $("#webtitle").text("");
    var uid = userinfo.id;
    $("#webiframe").attr("src","chatplugs.html?uid="+uid+"&fid="+fid);
}

function ownpage(el){
    $("#showimg").css({"left":"0px","top":"0px"});
    changePage("imgshow");
    $("#showimg").attr("src",el.src);
    var imgcontaner = document.getElementById("showimg");
    var hammertime = Hammer(imgcontaner, {
        preventDefault: true
    });
    var lastScale = 1;
    var startX = 0;
    var startY = 0;
    var changeX = 0;
    var changeY = 0;
    var currentX = 0;
    var currentY = 0;
    var hasDoubleTap = false;
    hammertime.on("transform",function(ev){
        $(imgcontaner).css({"transform":"scale("+ev.gesture.scale*lastScale+","+ev.gesture.scale*lastScale+")"});
        lastScale = ev.gesture.scale;
        $("#showimg").css({"left":"0px","top":"0px"});
    });
    hammertime.on("dragstart",function(ev){
        $(imgcontaner).css({"transition": ""});
        startX = ev.gesture.center.clientX;
        startY = ev.gesture.center.clientY;
        currentX = $(imgcontaner).css("left").split("px")[0]*1;
        currentY = $(imgcontaner).css("top").split("px")[0]*1;
    });
    hammertime.on("drag",function(ev){
        changeX = ev.gesture.center.clientX-startX;
        changeY = ev.gesture.center.clientY-startY;
        $(imgcontaner).css("left",currentX+changeX);
        $(imgcontaner).css("top",currentY+changeY);
    });
    hammertime.on("doubletap",function(ev){
        $("#showimg").css({"left":"0px","top":"0px"});
        if(hasDoubleTap){
            $(imgcontaner).css({"transform":"scale(1,1)","transition": "all 200ms ease-in"});
            hasDoubleTap = false;
        }else{
            $(imgcontaner).css({"transform":"scale(6,6)","transition": "all 200ms ease-in"});
            hasDoubleTap = true;
        }

    });

}
function scanErweiCode(){
    openScanCode();
}

function openScanCode() { //打开微信扫一扫
    wx.miniProgram.navigateTo({url: '../scanCode/scanCode'});//跳转到小程序调用微信扫一扫页面
}
/*function openTxmap() {
    wx.miniProgram.navigateTo({url: '../myObj/myObj?lat='+focusshop.latitude+"&lng="+focusshop.longitude+"&address="+focusshop.address});//跳转到小程序调用微信扫一扫页面
}*/

var _currentPosition = {};
var locationTimmer = null;
function getPositionByBaidu(json){
    hideLoader();
    var info = JSON.parse(json);
    _currentPosition = info;
    $("#addr").val(info.addr);
    info.address = info.addr;
    info.uid = userinfo.id;
    info.username = userinfo.username;
    uploadLocation(info);
}

function uploadLocation(obj){
    ajaxCallback("uploadLocation",obj,function(data){

    },true);
}

function startLocationTimmer(){
    clearInterval(locationTimmer);
    locationTimmer = setInterval(function (){
        getLocation();
    },10000);
}

function getLocation(){
    myLocation.getLocation();
}

function toNaozhong(){
    myObj.openClock();
}

function toSearch(){
    changePage("searchpage");
}

var _xibie = [{title:'信息技术系'},{title:'治安系'},{title:'侦查系'},{title:'警务管理系'},{title:'森林消防系'},{title:'警务技战术系'},{title:'刑事科学技术系'}];
var _zhuanye = [{title:'信息技术系',major:'网络安全与执法'},{title:'信息技术系',major:'公安情报学'},{title:'治安系',major:'治安'},{title:'侦查系',major:'侦查'}
    ,{title:'警务技战术系',major:'特警'},{title:'警务技战术系',major:'警务技战术'},
    {title:'警务管理系',major:'警务管理'},{title:'森林消防系',major:'消防工程'},
    {title:'刑事科学技术系',major:' 刑事技术'},{title:'刑事科学技术系',major:' 视听技术'}];


function toggleZhuanye(){
    var title = $("#yuanxi").val();
    var newlist = [];
    for(var i=0;i<_zhuanye.length;i++){
        var obj = _zhuanye[i];
        if(obj.title==title){
            newlist.push(obj);
        }
    }
    $("#zhuanye").refreshShowSelectMenu(newlist,"选择专业","major","major");
}

window.addEventListener('message', function(event) {
    // 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
    var loc = event.data;
    if (loc && loc.module == 'locationPicker') {//防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
        var latlng = loc.latlng;
        var address = loc.poiaddress;
        $("#qdaddress").val(address);
        goback();
    }
}, false);


function toSelectAddressPage(){
    changePage('selectaddresspage');
}